﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using BusinessLogic;
using System.Data.SqlClient;
using System.Data;

namespace DataAccessLogic
{
    public static class PartListDataAccess
    {
        public static PartList GetServiceReportPartList(Guid serviceReportID)
        {
            PartList pl = null;
            
            if (serviceReportID != Guid.Empty)
            {
                List<SqlParameter> parms = new List<SqlParameter>();
                parms.Add(new SqlParameter("@SERVICEREPORTID", serviceReportID));

                DataTable dt = DataAccess.Get(StoredProcedures.USP_PART_GETBYSERVICEREPORTID, parms);

                if (dt != null)
                {
                    pl = new PartList();

                    foreach (DataRow row in dt.Rows)
                    {
                        Part p = new Part();
                        p.ID = DataAccess.CheckForGuidColumn(row, "ID");
                        p.Description = DataAccess.CheckForStringColumn(row, "DESCRIPTION");
                        p.Number = DataAccess.CheckForStringColumn(row, "NUMBER");
                        p.Price = DataAccess.CheckForDecimalColumn(row, "PRICE");
                        p.Quantity = DataAccess.CheckForIntColumn(row, "QUANTITY");

                        pl.Add(p);
                    }
                }
            }

            return pl;
        }
    }
}